import request from '../utils/request';
import {stringify} from 'qs';
import {apiPrefix} from '../config/config';

export function create(params) {
  return request(`${apiPrefix}/projects`, {
    method: 'POST',
    body: params,
  });
}

export function getPage(params) {
  return request(`${apiPrefix}/projects_page?${stringify(params)}`);
}

export function get(params) {
  return request(`${apiPrefix}/projects/${params}`);
}

export function update(params) {
  return request(`${apiPrefix}/projects/${params.id}`, {
    method: 'PUT',
    body: params.data,
  });
}

export function remove(params) {
  return request(`${apiPrefix}/projects/${params}`, {method: 'DELETE'});
}

export function removeByIds(params) {
  return request(`${apiPrefix}/projects_delete_by_ids?ids=${params.ids.toString()}`, {method: 'DELETE'});
}

export function saveLevel(params) {
  const id = params.id;
  delete params.id;
  return request(`${apiPrefix}/projects/${id}/level`, {
    method: 'PUT',
    body: params,
  });
}

export function saveStatus(params) {
  const id = params.id;
  delete params.id;
  return request(`${apiPrefix}/projects/${id}/status`, {
    method: 'PUT',
    body: params,
  });
}

export function setRecom(params) {
  return request(`${apiPrefix}/projects/${params.id}/recom?is_recom=${params.is_recom}`, {
    method: 'PUT',
  });
}
